#pragma once


VOID_NS1(nVoid)

template<class a_tElem>
class tAry : public vector<a_tElem>
{
public:

	typedef vector<a_tElem> tBase;
	typedef a_tElem tElem;

	tAry() 
		: vector<a_tElem>()
	{ }

	template<class a_tArg, class... a_tArgs>
	tAry(a_tArg a_Arg, a_tArgs... a_Args)
	{
		seCtor(*this, a_Arg, a_Args...);
	}

	tAry(tAry<a_tElem> const& a_RHS)
		: vector<a_tElem>(a_RHS)
	{ }

	tAry(vector<a_tElem> const& a_RHS)
		: vector<a_tElem>(a_RHS)
	{ }

	tAry& operator =(tAry<a_tElem> const& a_RHS)
	{
		this->vector<a_tElem>::operator =(a_RHS);
		return *this;
	}

	tAry& operator =(vector<a_tElem> const& a_RHS)
	{
		this->vector<a_tElem>::operator =(a_RHS);
		return *this;
	}

	int cLen() const
	{
		return (int)this->size();
	}

	operator bool() const
	{
		return this->size() > 0;
	}

	bool cHas(int a_Idx) const
	{
		return (0 <= a_Idx) && (a_Idx < this->cLen());
	}

	tAry<a_tElem> cSlice(int a_Start = 0, int a_Stop = -1) const
	{
		if (a_Start < 0) { a_Start = 0; }
		if (a_Stop < 0) { a_Stop = this->cLength(); }
		tAry<a_tElem> o_Rst;
		if (a_Start >= a_Stop) { return o_Rst; }
		for (int i = a_Start; i < a_Stop; ++i)
		{
			o_Rst.push_back(this->at(i));
		}
		return o_Rst;
	}

	int cFind(a_tElem const& a_Which, bool a_Rev = false) const
	{
		if (!a_Rev)
		{
			auto o_Iter = std::find(this->begin(), this->end(), a_Which);
			return (o_Iter == this->end()) ? -1 : int(o_Iter - this->begin());
		}
		auto o_Iter = std::find(this->rbegin(), this->rend(), a_Which);
		return (o_Iter == this->rend()) ? -1 : (this->cLength() - 1 - int(o_Iter - this->rbegin()));
	}

	/// a_fIs: bool f(a_tElem 元素, int 索引)
	template<class a_tLambda>
	int cFindIf(a_tLambda a_fIs, bool a_Rev = false) const
	{
		if (!a_Rev)
		{
			int o_Len = this->cLength();
			for (int i = 0; i < o_Len; ++i)
			{
				if (a_fIs(this->at(i), i))
				{
					return i;
				}
			}
		}
		else
		{
			for (int i = this->cLength() - 1; i >= 0; --i)
			{
				if (a_fIs(this->at(i), i))
				{
					return i;
				}
			}
		}
		return -1;
	}

	tAry& cInsert(int a_Idx, a_tElem const& a_Elem)
	{
		if (a_Idx >= (int)this->size())
		{
			this->push_back(a_Elem);
		}
		else
		{
			this->insert(this->begin() + max(a_Idx, 0), a_Elem);
		}
		return *this;
	}

	tAry& cErase(int a_Idx, int a_Cnt = 1)
	{
		if (a_Idx < 0) { return *this; }
		while ((a_Cnt > 0) && (a_Idx < this->cLen()))
		{
			this->erase(this->begin() + a_Idx);
			--a_Cnt;
		}
		return *this;
	}

	/// 删除全部满足条件的，返回删除个数
	/// a_fTodo: bool f(a_tElem 元素, int 索引)
	template<class a_tLambda>
	int cEraseAllIf(a_tLambda a_fTodo)
	{
		int o_Rst = 0;
		for (int i = this->cLen() - 1; i >= 0; --i)
		{
			if (a_fTodo(this->at(i), i))
			{
				this->erase(this->begin() + i);
				++o_Rst;
			}
		}
		return o_Rst;
	}

	tAry& cSort()
	{
		std::sort(this->begin(), this->end());
		return *this;
	}

	/// a_fCompare(a_tElem a_1, a_tElem a_2) -> -1, 0, +1
	template<class a_tLambda>
	tAry& cSort(a_tLambda a_fCompare)
	{
		std::sort(this->begin(), this->end(),
			[a_fCompare](a_tElem const& a_1, a_tElem const& a_2) -> bool
			{ return a_fCompare(a_1, a_2) <= 0; }
		);
		return *this;
	}

	//======================================================== 静态接口

	template<class a_tArg, class... a_tArgs>
	static void seCtor(vector<a_tElem>& a_Rst, a_tArg const& a_Arg, a_tArgs... a_Args)
	{
		a_Rst.push_back(a_tElem(a_Arg));
		seCtor(a_Rst, a_Args...);
	}

	static void seCtor(vector<a_tElem>& a_Rst)
	{ }

};



VOID_NS0(nVoid)